import {FormSchema} from "/@/components/Form";
import {h, unref} from "vue";
import {SgUpload} from "/@/components/SgUpload";
import {uploadEXCEL} from "/@/api/sys/user";

export const formSchema: FormSchema[] = [
  {
    field: 'deptId',
    label: '班级ID',
    component: 'Input',
    required: true,
    show: false
  },
  // {
  //   label: 'JSON 格式',
  //   field: 'jsonFile',
  //   component: 'Input',
  //   render: ({model, field}) => {
  //     return h(SgUpload, {
  //       value: model[field],
  //       api: uploadJSON,
  //       type: 'json',
  //       accept: '.json',
  //       showFileList: false,
  //       handleFormData: (formData) => {
  //         const {data} = formData;
  //         // 增加分类 ID 参数
  //         Object.assign(data, {deptId: model['deptId']});
  //       },
  //       handleDone: (value) => {
  //         if (value) {
  //           model[field] = unref(value).id;
  //         }
  //       },
  //     });
  //   },
  // },
  {
    label: 'EXCEL 格式',
    field: 'excelFile',
    component: 'Input',
    render: ({model, field}) => {
      return h(SgUpload, {
        value: model[field],
        api: uploadEXCEL,
        type: 'excel',
        accept: '.xlsx',
        showFileList: false,
        handleFormData: (formData) => {
          const {data} = formData;
          // 增加分类 ID 参数
          Object.assign(data, {deptId: model['deptId']});
        },
        handleDone: (value) => {
          if (value) {
            model[field] = unref(value).id;
          }
        },
      });
    },
  },
]
